<html>
	<head>
		<!-- jquery is included for form reset to work in Firefox -->
		<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
	</head>
<body>
	
<h1>Purchase Ticket Verification Test Tool</h2>
<hr/>
<h3>
Click Here To Reset Forms after Payment Request Verification Submission
</h3>
<form id="form">
 <p>
<input type="submit" value="Reset" />
</p>
</form>
<hr/>
 
<!---
Right after the form HTML has been rendered, set a timeout
for the form reset. A slight timeout is needed for this
code to work in Internet Explorer.
--->
<script type="text/javascript">
setTimeout(function(){document.getElementById( "form" ).reset();},5);
 </script>


<h3>Request Purchase Ticket Verification</h3>
Payment Verification Request URL: <input size="150" type="text" name="purchaseUrl" id="purchaseUrl"/>
<br>
Transaction ID: <input size="150" type="text" name="transactionId" id="transactionId"/>
<br>
Transaction Time: <input size="150" type="text" name="transactionTime" id="transactionTime"/>
<br>
Product Id: <input size="150" type="text" name="productId" id="productId"/>
<br>
Application Id: <input size="150" type="text" name="applicationId" id="applicationId"/>
<br>
Account Id: <input size="150" type="text" name="accountId" id="accountId"/>
<br>
imei: <input size="150" type="text" name="imei" id="imei"/>
<br>
imsi: <input size="150" type="text" name="imsi" id="imsi"/>
<br>
Signature: <input size="150" type="text" name="signature" id="signature"/>
<br>
<br/>
<button type="button" onclick="getPurchaseTicketVerification()">Request Payment Ticket Verification</button>
Payment Request URL (auto-generated): <br/><textarea rows="3" cols="100" name="xmlResponse" id="xmlResponse" readonly=true> </textarea>
<br/>
Payment Response Body (auto-generated):<br/>
<form name="authForm" id="authForm" method="post" target="ifr" action=""> </form>
<iframe name="ifr" id="ifr" width="700" height="100"> </iframe>
<hr/>


<h3>Request Binary Purchase Ticket Verification</h3>
Binary Payment Verification Request URL: <input size="150" type="text" name="binaryPurchaseUrl" id="binaryPurchaseUrl"/>
<br>
Binary Purchase Ticket: <input size="150" type="text" name="binaryPurchaseTicketId" id="binaryPurchaseTicketId"/>
<br>
<br/>
<button type="button" onclick="getBinaryPurchaseTicketVerification()">Request Binary Payment Ticket Verification</button>
Payment Request URL (auto-generated): <br/><textarea rows="3" cols="50" name="xmlResponseBinary" id="xmlResponseBinary" readonly=true> </textarea>
<br/>
Payment Response Body (auto-generated):<br/>
<form name="authForm2" id="authForm2" method="post" target="ifr2" action=""> </form>
<iframe name="ifr2" id="ifr2" width="700" height="100"> </iframe>
<hr/>

<script type="text/javascript">



   function initEnv(){
      var serverURL_prefix = "https://payment.ovi.com";
	  
      document.getElementById("purchaseUrl").value = serverURL_prefix + '/iap/1.0/purchases/verify?method=GET';
	  document.getElementById("transactionId").value = '';
	  document.getElementById("transactionTime").value = '';
	  document.getElementById("productId").value = '';
	  document.getElementById("applicationId").value = '';
	  document.getElementById("accountId").value = '';
	  document.getElementById("imei").value = '';
	  document.getElementById("imsi").value = '';
	  document.getElementById("signature").value = '';
	  
	  document.getElementById("binaryPurchaseUrl").value = serverURL_prefix + '/iap/1.0/purchases/verify?method=GET';
	  document.getElementById("binaryPurchaseTicketId").value = '';
	  
   }

   initEnv();

   function getPurchaseTicketVerification() {
      var serverUrl = document.getElementById('purchaseUrl').value;
	  var transactionId = document.getElementById('transactionId').value;
      var transactionTime = document.getElementById('transactionTime').value;
      var productId = document.getElementById('productId').value;
      var applicationId = document.getElementById('applicationId').value;
      var accountId = document.getElementById('accountId').value;
	  var imei = document.getElementById('imei').value;
      var imsi = document.getElementById('imsi').value;
      var signature = document.getElementById('signature').value;

	  var theTicket = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
	  		+'<PurchaseVerificationRequest xmlns="http://payment.ovi.com/iap">'
			+'<PurchaseTicket transactionId="'
			+transactionId
			+'" transactionTime="'
			+transactionTime
			+'" productId="'
			+productId
			+'" applicationId="'
			+applicationId
			+'" accountId="'
			+accountId
			+'" imei="'
			+imei
			+'" imsi="'
			+imsi
			+'" signature="'
			+signature
			+'"/></PurchaseVerificationRequest>';

	  post_to_url_Form1(serverUrl, {'content' : theTicket} );
	  
	  document.getElementById('xmlResponse').value = serverUrl;
	  
   }


	function getBinaryPurchaseTicketVerification() {
      var serverUrl = document.getElementById('binaryPurchaseUrl').value;
	  var binaryPurchaseTicketId = document.getElementById('binaryPurchaseTicketId').value;
 	
	  
	  var theTicket = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><PurchaseVerificationRequest xmlns="http://payment.ovi.com/iap"><Binary>'
	  					+ binaryPurchaseTicketId
	  					+ '</Binary></PurchaseVerificationRequest>';
	  
	  post_to_url_Form2(serverUrl, {'content' : theTicket} );
	  document.getElementById('xmlResponseBinary').value = serverUrl;
	  
   }

   function post_to_url_Form1(path, params, method) {
	    method = method || "post"; // Set method to post by default, if not specified.

	    var form = document.authForm;
	    form.setAttribute("method", method);
	    form.setAttribute("action", path);
	
	    for(var key in params) {
	        var hiddenField = document.createElement("input");
	        hiddenField.setAttribute("type", "hidden");
	        hiddenField.setAttribute("name", key);
	        hiddenField.setAttribute("value", params[key]);
	
	        form.appendChild(hiddenField);
	    }
	
	    document.body.appendChild(form);
	    form.submit();
   }

   function post_to_url_Form2(path, params, method) {
	    method = method || "post"; // Set method to post by default, if not specified.

	    var form = document.authForm2;
	    form.setAttribute("method", method);
	    form.setAttribute("action", path);
	
	    for(var key in params) {
	        var hiddenField = document.createElement("input");
	        hiddenField.setAttribute("type", "hidden");
	        hiddenField.setAttribute("name", key);
	        hiddenField.setAttribute("value", params[key]);
	
	        form.appendChild(hiddenField);
	    }
	
	    document.body.appendChild(form);
	    form.submit();
   }

   
	function getNonce(length) 
	{    
		var nonceChars = "0123456789abcdefghijklmnopqrstuvwxyz";    
		var nonce = "";    
		for (var i = 0; i < length; i++) 
		{        
			nonce += nonceChars.charAt(Math.floor(Math.random() * nonceChars.length));    
		}    
	return nonce;}
	
	
   function getTimestamp() {
      return '' + Math.floor(new Date().getTime() / 1000);
   }


</script>

</body>
</html>